var e = function (e) {
  return (e = e.toString())[1] ? e : "0" + e;
};
import {config } from './config.js'
module.exports = {
  formatTime: function (t) {
    var r = t.getFullYear(),
        a = t.getMonth() + 1,
        n = t.getDate(),
        u = t.getHours(),
        s = t.getMinutes(),
        o = t.getSeconds();
    return [r, a, n].map(e).join("/") + " " + [u, s, o].map(e).join(":");
  },
  formatTimeTwo: function (t, r) {
    var a = ["Y", "M", "D", "h", "m", "s"],
        n = [],
        u = new Date(t);
    n.push(u.getFullYear()), n.push(e(u.getMonth() + 1)), n.push(e(u.getDate())), n.push(e(u.getHours())), n.push(e(u.getMinutes())), n.push(e(u.getSeconds()));

    for (var s in n) r = r.replace(a[s], n[s]);

    return r;
  },
  ERR_OK: "0000",
  calcLastTime: function (e) {
    var t = new Date().getTime(),
        r = Object.create(null);
    return t >= e ? (r.day = 0, r.hour = 0) : (r.day = parseInt((e - t) / 864e5), r.hour = parseInt((e - t - 24 * r.day * 60 * 60 * 1e3) / 36e5)), r;
  },
  isIdCardNo: function (e) {
    if (e = e.toUpperCase(), !/(^\d{15}$)|(^\d{17}([0-9]|X|x)$)/.test(e)) return !1;
    var t, r;

    if (15 == (t = e.length)) {
      if (r = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/), s = e.match(r), (o = new Date("19" + s[2] + "/" + s[3] + "/" + s[4])).getYear() == Number(s[2]) && o.getMonth() + 1 == Number(s[3]) && o.getDate() == Number(s[4])) {
        var a = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2),
            n = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"),
            u = 0;

        for (e = e.substr(0, 6) + "19" + e.substr(6, e.length - 6), g = 0; g < 17; g++) u += e.substr(g, 1) * a[g];

        return e += n[u % 11];
      }

      return !1;
    }

    if (18 == t) {
      r = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$/);
      var s = e.match(r),
          o = new Date(s[2] + "/" + s[3] + "/" + s[4]);

      if (o.getFullYear() == Number(s[2]) && o.getMonth() + 1 == Number(s[3]) && o.getDate() == Number(s[4])) {
        var g,
            a = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2),
            n = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"),
            u = 0;

        for (g = 0; g < 17; g++) u += e.substr(g, 1) * a[g];

        return n[u % 11] == e.substr(17, 1) && e;
      }

      return !1;
    }

    return !1;
  },
  bMapTransQQMap: function (e, t) {
    var r = 52.35987755982988,
        a = e - .0065,
        n = t - .006,
        u = Math.sqrt(a * a + n * n) - 2e-5 * Math.sin(n * r),
        s = Math.atan2(n, a) - 3e-6 * Math.cos(a * r);
    return {
      lng: u * Math.cos(s),
      lat: u * Math.sin(s)
    };
  },
  formatSelectOption: function(resp) {
    var result = [];
	if (resp.data.data.length > 0) {
		resp.data.data.forEach(function(single) {
			result.push({name: single.value, value: single.code});
		});
	}
	
	return result;
  },
	
	formatImgUrl: function(imageUrl, host) {
		return imageUrl ? host + "/sysFileInfo/preview?id=" + imageUrl : "/static/images/defaultorg.png";
	},
	
	imageUrl: function(id) {
		return id ? config.host + "/sysFileInfo/preview?id=" + id : "/static/images/defaultnews.jpg";
	}
};